package com.bdqn.jiang.Service.impl;

import com.bdqn.jiang.Service.BaseService;
import com.bdqn.jiang.entity.User;



import java.util.List;
import java.util.Scanner;

public class RegisterServiceImpl implements BaseService {
    Scanner sc = new Scanner(System.in);

    User user = new User();

    @Override
    public void execute(List list) {
        for (; ; ) {

            System.out.println("请输入登录名");
            String name = sc.next();
            System.out.println("请输入密码");
            String pwd = sc.next();
            System.out.println("再次输入密码");
            String pwd1 = sc.next();
//            if (name==null&&pwd==null&&pwd1==null){
//                System.out.println("不能为空");
//                continue;
//            }


            if (pwd.equals(pwd1)) {

            } else {
                System.out.println("两次密码不一样请重新输入");
                continue;

            }

            user.setUsername(name);
            user.setUserpwd(pwd);

            int result = insert(list);

            if (result == 1) {
                System.out.println("注册成功！");
                list.add(user);
                System.out.println(user.getUsername());
                System.out.println(user.getUserpwd());
                break;

            } else {
                System.out.println("注册失败！已经注册该用户了！");
                break;
            }


        }



    }



//        if (user.getUsername()!=name &&user.getUserpwd()!=pwd){
//            System.out.println("账号或密码错误");
//        }





    public int insert(List list) {

        for (int i = 0; i <list.size() ; i++) {

            User user1=(User) list.get(i);
            if(user1.getUsername().equals(user.getUserpwd())){
                return 0;
            }
        }
        return 1;
    }



}
